package com.szzg10.thinking.chapter11;

import java.util.Iterator;

public class NonCollectionSequence extends PetSequence {

	public static void main(String[] args) {
		NonCollectionSequence nonCollectionSequence = new NonCollectionSequence();
		InterfaceVsInterator.display(nonCollectionSequence.iterator());
	}
	
	public Iterator<Pet> iterator() {
		return new Iterator<Pet>() {
			int index = 0;
			
			@Override
			public boolean hasNext() {
				return pets.length > index;
			}

			@Override
			public Pet next() {
				return pets[index++];
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}
}

class PetSequence {
	protected Pet[] pets = {new Rat(), new Manx(), new Cymric(), new Mutt(), new Pug(), new Cymric(), new Pug(), new Manx()};
}